/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services.impl;

import domain.Users;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import services.interfaces.IUserServices;

/**
 *
 * @author amega
 */
@Stateless
@LocalBean
public class UserServiceImpl extends GenericServiceImpl<Users> implements IUserServices{

    @PersistenceContext(unitName="RGHPU")
    private EntityManager em;
    
    
    public UserServiceImpl() {
        super(Users.class);
    }
    
    @Override
    protected EntityManager getEntityManager() {
        return this.em;
    }
    
    public Users getUserByEmailAndPassword(String email,String password) {
        try {
            Query q = em.createNamedQuery("Users.findByEmailAndPass").setParameter("email", email).setParameter("password", password);
            Users u = (Users)q.getSingleResult();
             return u;
        } catch (Exception e) {
            return  null;
        }
    } 
    
    
    public Users getUserByEmail(String email) {
       try {
            Query q = em.createNamedQuery("Users.findByEmail").setParameter("email", email);
            Users u = (Users)q.getSingleResult();
             return u;
        } catch (Exception e) {
            return  null;
        } 
    }
}
